//
//  SDHuiYuVC.m
//  SDHuiYuShoping
//
//  Created by luojiao on 2017/4/12.
//  Copyright © 2017年 luojiao. All rights reserved.
//

#import "SDHuiYuVC.h"
#import "SDHuiYuTableViewCell.h"
#import "PageViewController.h"

#import "OrderViewController.h"
#import "ExchangeViewController.h"


@interface SDHuiYuVC ()<UITableViewDelegate,UITableViewDataSource>

{
    NSMutableArray *investmentArr;//投资概况
    NSMutableArray *membersArr;//会员
    NSMutableArray *personInfoAndNoticeArr;//个人信息和通知
    NSMutableArray *giftsArr;//赠品订单
    
}
@end

@implementation SDHuiYuVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.hidden = YES;
    if (![FRUtils isLogin])
    {
        [FRUtils presentToLoginViewControllerWithRootViewController:self];
    }
    [self.myPageButton setImage:[UIImage imageNamed:@"open"] forState:UIControlStateNormal];
    [self.myPageButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -150)];
    [self.myPageButton setTitle:@"主面板" forState:UIControlStateNormal];
    [self.myPageButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    self.headerImage.image = [FRUtils circleImage:[UIImage imageNamed:@"avatar"] withParam:1];
    
    self.tableView.tableHeaderView = self.headerView;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = NO;
    
    investmentArr = [[NSMutableArray alloc] initWithObjects:@"拍单功能",@"排单币兑换",@"交易记录",@"我要提现",@"申请复投", nil];
    membersArr = [[NSMutableArray alloc] initWithObjects:@"推荐会员",@"会员家族",@"推荐码/推荐链接", nil];
    personInfoAndNoticeArr = [[NSMutableArray alloc] initWithObjects:@"个人首页",@"公告列表", nil];
    giftsArr = [[NSMutableArray alloc] initWithObjects:@"赠品选择",@"赠品订单列表", nil];
}

- (IBAction)myPageButton:(id)sender {
    PageViewController *pageViewController = [[PageViewController alloc] init];
    [self.navigationController pushViewController:pageViewController animated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //设置状态栏颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

#pragma mark - UITableViewDelegate && UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 5;
    }
    else if (section ==1)
    {
        return 3;
    }
    else if (section == 2 || section == 4)
    {
        return 1;
    }
    else
    {
        return 2;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 15.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SDHuiYuTableViewCell *cell;
    static NSString *cellIdentifier = @"HuiYuCell";
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell)
    {
        cell = [[NSBundle mainBundle] loadNibNamed:@"SDHuiYuTableViewCell" owner:self options:nil][0];
    }
    
    NSString *name;
    //设置cell显示内容
    if (indexPath.section == 0)
    {
        cell.headerView.image = [FRUtils resizeImageWithImageName:@"investment_logo"];
        name = [investmentArr objectAtIndex:indexPath.row];
        cell.nameLabel.text = name;
    }
    else if (indexPath.section == 1)
    {
        cell.headerView.image = [FRUtils resizeImageWithImageName:@"member_logo"];
        name = [membersArr objectAtIndex:indexPath.row];
        cell.nameLabel.text = name;
    }
    else if (indexPath.section == 2)
    {
        cell.headerView.image = [FRUtils resizeImageWithImageName:@"personal_logo"];
        name = [personInfoAndNoticeArr objectAtIndex:0];
        cell.nameLabel.text = name;
    }
    else if (indexPath.section == 3)
    {
        cell.headerView.image = [FRUtils resizeImageWithImageName:@"gift_logo"];
        name = [giftsArr objectAtIndex:indexPath.row];
        cell.nameLabel.text = name;
    }
    else
    {
        cell.headerView.image = [FRUtils resizeImageWithImageName:@"notice_logo"];
        name = [personInfoAndNoticeArr lastObject];
        cell.nameLabel.text = name;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 15)];
    footerView.backgroundColor = [FRUtils colorWithHexString:@"#f0f0f0"];
    return footerView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section ==0)
    {
        if (indexPath.row == 0)
        {
            OrderViewController *orderViewController = [[OrderViewController alloc] init];
            [self.navigationController pushViewController:orderViewController animated:YES];
        }
        else if (indexPath.row == 1)
        {
            ExchangeViewController *exchangeViewController = [[ExchangeViewController alloc] init];
            [self.navigationController pushViewController:exchangeViewController animated:YES];
        }
        else if (indexPath.row == 2)
        {}
        else if (indexPath.row == 3)
        {}
        else
        {}
    }
    else if (indexPath.section == 1)
    {
        if (indexPath.row == 0)
        {
            
        }
        else if (indexPath.row == 1)
        {}
        else
        {}
    }
    else if (indexPath.section == 2)
    {
        
    }
    else if (indexPath.section == 3)
    {
        if (indexPath.row == 0)
        {
        }
        else if (indexPath.row == 1)
        {}
        else
        {}
    }
    else {
        
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
